/*---------------------------------------------------------
  Oren Attia  - 29074333
  Doron Segal - 
  ---------------------------------------------------------*/

#include <windows.h>
#include <commctrl.h>

#define IDC_MAIN_EDIT					10001
#define IDC_MAIN_TOOL					10002
#define IDC_MAIN_STATUS					10003

#define IDC_BLACK                       20001
#define IDC_BLUE                        20002
#define IDC_GREEN                       20003
#define IDC_CYAN                        20004
#define IDC_RED                         20005
#define IDC_MAGENTA                     20006
#define IDC_YELLOW                      20007
#define IDC_WHITE                       20008

#define ID_DRAW_LINE                    30001
#define ID_DRAW_SQUARE                  30002
#define ID_DRAW_ELLIPSE                 30003

#define ID_CLEAR                        40001
#define ID_FILE_SAVEAS                  40002
#define ID_FILE_OPEN                    40013
#define ID_FILL_SHAPE                   40004
#define ID_EMPTY_SHAPE                  40005
#define ID_UNDO                         40006
#define ID_REDO                         40007
#define ID_EXIT                         40008

#define ID_CHOOSE_COLOR                 41001
#define ID_CHOOSE_SHAPE                 41002

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

HINSTANCE gHinst;
COLORREF gColor;

const char szClassName[] = "PaintBrush_WindowClass";

static int pShape=ID_DRAW_LINE; 
static RECT rcMain,rcShape;
static HBRUSH hBrush,holdBrush ;
static HPEN hPen,holdPen ;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;

	//InitCommonControls();

	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.style		 = 0;
	wc.lpfnWndProc	 = WndProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor		 = LoadCursor(NULL, IDC_CROSS);
	wc.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(210,180,140));
	wc.lpszMenuName  = NULL;											
	wc.lpszClassName = szClassName;
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);

	gHinst = hInstance;

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, "Window Registration Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	hwnd = CreateWindowEx(
		0,
		szClassName,
		"HIT Final Project - Paint Brush Application",
		WS_OVERLAPPEDWINDOW ,
		CW_USEDEFAULT, CW_USEDEFAULT, 623,470,
		NULL, NULL, hInstance, NULL);

	if(hwnd == NULL)
	{
		MessageBox(NULL, "Window Creation Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static int   cxChar, cyChar ;

    HDC         hdc = (HDC) wParam ;
    PAINTSTRUCT ps ;
	RECT		rcColors;

	switch(msg)
	{
	 case WM_CREATE:
		 {
		 }
		 break;
     case WM_CTLCOLORSTATIC: 
		 {   
		 }
		 break;
     case WM_LBUTTONDOWN:
		 {   
		 }
		 break;
     case WM_MOUSEMOVE:
		 {
		 }
		 break;
     case WM_LBUTTONUP:
		 {
		 }
	     break;
	 case WM_SIZE:
		 {
		 }
	     break;
	 case WM_PAINT: 
		 {
		 }
	     break;
	 case WM_CLOSE:
		 {
			 DestroyWindow(hwnd);
		 }
		 break;
	 case WM_DESTROY:
		 {
			 PostQuitMessage(0); 
		 }
		 break;
	 case WM_COMMAND:
		 {
			 switch(LOWORD(wParam))
			 {
				case ID_CLEAR:
					
				break;
				case ID_FILE_OPEN:
					//DoFileOpen(hwnd);
				break;
				case ID_FILE_SAVEAS:
					//DoFileSave(hwnd);
				break;
				break;
				case ID_DRAW_LINE:
					pShape=ID_DRAW_LINE;
				break; 
				case ID_DRAW_SQUARE:
					pShape=ID_DRAW_SQUARE;
				break; 
				case ID_DRAW_ELLIPSE:
					pShape=ID_DRAW_ELLIPSE;
				break; 
				case ID_EXIT:
					SendMessage(hwnd,WM_CLOSE,0,0L);
				break; 

				if (HIWORD(wParam) == BN_CLICKED) 
				{
					switch (LOWORD(wParam)) 
					{
						case IDC_BLACK:
							gColor = RGB(0, 0, 0);
						break; 
						case IDC_BLUE:
							gColor = RGB(0, 76, 255);
						break; 
						case IDC_GREEN:
							gColor = RGB(34, 139, 34);
						break; 
						case IDC_CYAN:
							gColor = RGB(0, 255, 255);
						break; 
						case IDC_RED:
							gColor = RGB(255, 0, 0);
						break; 
						case IDC_MAGENTA:
							gColor = RGB(255, 0, 255);
						break; 
						case IDC_YELLOW:
							gColor = RGB(255, 255, 0);
						break; 
						case IDC_WHITE:
							gColor = RGB(255, 255, 255);
						break; 
					}
					InvalidateRect(hwnd, NULL, FALSE);
				}
			 }
		 }
		 break;		
	 default:
		 return DefWindowProc(hwnd, msg, wParam, lParam);
	}

return 0;
}
